package ar.com.angrymachine.hunter.activities;

import ar.com.angrymachine.hunter.Activity;

public abstract class IncrementalActivity extends Activity
{
    protected int currentTime = 0;
    protected abstract int getCompletionTime();
    
    protected int getFinalIncrement(int delta)
    {
        return delta;
    }
    
    protected abstract boolean onCompletion(); // returns if the activity should be removed
    
    public void update(int delta, boolean action, boolean timeIsRunning)
    {
        if(timeIsRunning)
        {
            if(action)
            {
                currentTime += getFinalIncrement(delta);
                if(currentTime >= getCompletionTime())
                {
                	currentTime = getCompletionTime();
                    if(onCompletion())
                    {
                    	end(true);
                    }
                }
            }
        }
    }
    
    public void reset()
    {
    	currentTime = 0;
    }

    public boolean isCompleted()
    {
        return currentTime >= getCompletionTime();
    }
}
